package com.xiaotu.service.auth.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.xiaotu.dao.auth.SwAuthMapper;
import com.xiaotu.dao.user.WxUserMapper;
import com.xiaotu.dto.SwAuthDto;
import com.xiaotu.dto.WxUserDto;
import com.xiaotu.model.SwAuthModel;
import com.xiaotu.service.auth.SwAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zhangxiao
 * @create 2021-08-19 15:38
 */
@Transactional
@Service
public class SwAuthServiceImpl implements SwAuthService<SwAuthDto> {

    @Autowired
    private SwAuthMapper swAuthMapper;

    @Autowired
    private WxUserMapper wxUserMapper;

    @Override
    public void submitAuth(SwAuthDto swAuth) {
        SwAuthModel swAuthModel = new SwAuthModel();
        BeanUtil.copyProperties(swAuth, swAuthModel);
        if (ObjectUtil.isNull(swAuth.getAuthId())) {
            swAuthMapper.insert(swAuthModel);
        } else {
            //将状态设置为 认证中
            WxUserDto wxUserDto = new WxUserDto();
            wxUserDto.setAuthStatus(1);
            wxUserDto.setUserId(swAuth.getUserId());
            wxUserMapper.updateByPrimaryKeySelective(wxUserDto);
            swAuthMapper.updateByPrimaryKey(swAuthModel);
        }
    }

}
